import 'auth_token.dart';
import 'user.dart';

class LoginRequest {
  final String username;
  final String password;
  final bool rememberMe;

  LoginRequest({
    required this.username,
    required this.password,
    this.rememberMe = false,
  });

  Map<String, dynamic> toJson() {
    return {
      'username': username,
      'password': password,
      'rememberMe': rememberMe,
    };
  }

  @override
  String toString() {
    return 'LoginRequest{username: $username, rememberMe: $rememberMe}';
  }
}

class LoginResponse {
  final AuthToken token;
  final User user;
  final String message;

  LoginResponse({
    required this.token,
    required this.user,
    this.message = '登录成功',
  });

  factory LoginResponse.fromJson(Map<String, dynamic> json) {
    return LoginResponse(
      token: AuthToken.fromJson(json['token'] ?? json),
      user: User.fromJson(json['user'] ?? json),
      message: json['message'] ?? '登录成功',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'token': token.toJson(),
      'user': user.toJson(),
      'message': message,
    };
  }
}

class RegisterRequest {
  final String username;
  final String email;
  final String password;
  final String confirmPassword;
  final String? displayName;
  final String? partnerName;
  final DateTime? relationshipStartDate;

  RegisterRequest({
    required this.username,
    required this.email,
    required this.password,
    required this.confirmPassword,
    this.displayName,
    this.partnerName,
    this.relationshipStartDate,
  });

  Map<String, dynamic> toJson() {
    return {
      'username': username,
      'email': email,
      'password': password,
      'confirmPassword': confirmPassword,
      if (displayName != null) 'displayName': displayName,
      if (partnerName != null) 'partnerName': partnerName,
      if (relationshipStartDate != null)
        'relationshipStartDate': relationshipStartDate!.toIso8601String(),
    };
  }

  @override
  String toString() {
    return 'RegisterRequest{username: $username, email: $email}';
  }
}

class ForgotPasswordRequest {
  final String email;

  ForgotPasswordRequest({required this.email});

  Map<String, dynamic> toJson() {
    return {'email': email};
  }
}